* Put your path to the repository *
cd "/Replication files/"

clear
use Data_IPD

tsset ID_dyad Round

* * * * Overview of the experiment * * * *  

* * Fig. 2 Boxplot of the level of individual attack against an outgroup by round * * 

graph box Attack_subj_outgroup if Atleast_one_group_dead != 1, over(Round) by(UDC) 

* * Fig. 3 Mean resources of the five playing groups by round * *

keep Resources_ingroup Round ID_ingroup UDC Attack_ingroup_outgroup Rank_ingroup

duplicates drop 

gen Rank_1 = Rank_ingroup if Round == 1
sort ID_ingroup Round 
by ID_ingroup, sort: replace Rank_1 = Rank_1[_n-1] if Rank_1 == .

egen mean = mean(Resources_ingroup), by(Rank_1 Round UDC)
egen sd = sd(Resources_ingroup), by(Rank_1 Round UDC)
gen upper = mean + sd
gen lower = mean - sd

keep mean Round upper lower UDC Rank_1
duplicates drop

scatter mean Round, by(Rank_1) connect(L) msymbol(diamond) mcolor(blue) msize(small) lcolor(blue) yscale(range(500 2500)) ymtick(500(500)2500) ylabel(500(500)2500) || rspike upper lower Round, by(UDC) lpattern(dot) lcolor(blue) lwidth(medthick)


* * * * Confirmatory analyses * * * *

clear
use Data_IPD

tsset ID_dyad Round

* * * Descriptive statistics * * *

* * Tab. 3 Mean level of individual attacks against an outgroup depending on the experimental treatment and the outgroup economic condition * *

tabulate UDC Ecocond_outgroup if Atleast_one_group_dead != 1, summarize(Attack_subj_outgroup) 
tabulate UDC Ecocond_outgroup if Atleast_one_group_dead != 1, summarize(Attack_subj_outgroup_richer) 
tabulate UDC Ecocond_outgroup if Atleast_one_group_dead != 1, summarize(Attack_subj_outgroup_poorer) 

* * Fig. 4 Boxplot of the level of individual attacks against an outgroup depending on the experimental treatment and the outgroup economic condition * *

graph box Attack_subj_outgroup Attack_subj_outgroup_richer Attack_subj_outgroup_poorer if Atleast_one_group_dead != 1, over(Ecocond_outgroup) by(UDC) 

* * * Envy hypothesis * * *

* * Fig. 5 Level of individual attacks against an outgroup depending on the outgroup resources * * 

scatter Attack_subj_outgroup Resources_outgroup if Atleast_one_group_dead != 1, by(UDC) jitter(1) || qfitci Attack_subj_outgroup Resources_outgroup  if Atleast_one_group_dead != 1, by(UDC) clcolor(black)

* * Negative binomial regression * * 

menbreg Attack_subj_outgroup i.Richer_outgroup Attack_outgroup_ingroup_lag_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject:
outreg2 using menbreg_confirmatory, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg Attack_subj_outgroup i.UDC Attack_outgroup_ingroup_lag_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject:
outreg2 using menbreg_confirmatory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg Attack_subj_outgroup i.Richer_outgroup##i.UDC Attack_outgroup_ingroup_lag_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject:
outreg2 using menbreg_confirmatory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

* * * Jealousy hypothesis * * *

* * Negative binomial regression * * 

menbreg Attack_subj_outgroup i.Ecocond_outgroup_improving Attack_outgroup_ingroup_lag_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject:
outreg2 using menbreg_confirmatory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg Attack_subj_outgroup i.Richer_outgroup##i.Ecocond_outgroup_improving Attack_outgroup_ingroup_lag_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject:
outreg2 using menbreg_confirmatory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg Attack_subj_outgroup i.Richer_outgroup##i.UDC##i.Ecocond_outgroup_improving Attack_outgroup_ingroup_lag_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject:
outreg2 using menbreg_confirmatory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

* * FIg. 6 mean level of individual attacks by outgroup economic condition based on the last model. Note: I use xtnbreg instead of menbreg (an equivalent multilevel-nbreg command) because bug when computing margins after menbreg * *

xtset ID_subject 

xtnbreg Attack_subj_outgroup i.Richer_outgroup##i.UDC##i.Ecocond_outgroup_improving Attack_outgroup_ingroup_lag_std i.Rank_ingroup if Atleast_one_group_dead != 1 
margins Ecocond_outgroup_improving, atmeans at(UDC=(0(1)1)  Richer_outgroup =(0(1)1)) predict(nu0) 


* * * * Exploratory analyses * * * *

menbreg  Attack_subj_outgroup c.Me_coop_std c.Left_right_std c.SDO_std Gender Age_std i.Educ i.Work i.Richer_outgroup Resources_outgroup_std c.Varia_Ecocond_outgroup_std c.Inequality_std i.UDC Attack_subj_outgroup_lag_std Attack_outgroup_ingroup_lag_std Attack_othingroupplayers_lag_std Resources_subj_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject: 
outreg2 using menbreg_exploratory, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg  Attack_subj_outgroup c.Me_coop_std##i.Richer_outgroup c.Left_right_std c.SDO_std Gender Age_std i.Educ i.Work Resources_outgroup_std c.Varia_Ecocond_outgroup_std c.Inequality_std i.UDC Attack_subj_outgroup_lag_std Attack_outgroup_ingroup_lag_std Attack_othingroupplayers_lag_std Resources_subj_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject: Richer_outgroup
outreg2 using menbreg_exploratory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg  Attack_subj_outgroup c.Me_coop_std c.Left_right_std##i.Richer_outgroup c.SDO_std Gender Age_std i.Educ i.Work Resources_outgroup_std c.Varia_Ecocond_outgroup_std c.Inequality_std i.UDC Attack_subj_outgroup_lag_std Attack_outgroup_ingroup_lag_std Attack_othingroupplayers_lag_std Resources_subj_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject: Richer_outgroup
outreg2 using menbreg_exploratory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg  Attack_subj_outgroup c.Me_coop_std c.Left_right_std c.SDO_std##i.Richer_outgroup Gender Age_std i.Educ i.Work Resources_outgroup_std c.Varia_Ecocond_outgroup_std c.Inequality_std i.UDC Attack_subj_outgroup_lag_std Attack_outgroup_ingroup_lag_std Attack_othingroupplayers_lag_std Resources_subj_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject: Richer_outgroup
outreg2 using menbreg_exploratory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg  Attack_subj_outgroup c.Me_coop_std c.Left_right_std c.SDO_std Gender Age_std i.Educ i.Work Resources_outgroup_std c.Varia_Ecocond_outgroup_std c.Inequality_std##i.Richer_outgroup i.UDC Attack_subj_outgroup_lag_std Attack_outgroup_ingroup_lag_std Attack_othingroupplayers_lag_std Resources_subj_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject:
outreg2 using menbreg_exploratory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 

menbreg  Attack_subj_outgroup c.Me_coop_std##i.Richer_outgroup c.Left_right_std##i.Richer_outgroup c.SDO_std##i.Richer_outgroup Gender Age_std i.Educ i.Work Resources_outgroup_std c.Varia_Ecocond_outgroup_std c.Inequality_std##i.Richer_outgroup i.UDC Attack_subj_outgroup_lag_std Attack_outgroup_ingroup_lag_std Attack_othingroupplayers_lag_std Resources_subj_std i.Rank_ingroup if Atleast_one_group_dead != 1 || ID_subject: Richer_outgroup
outreg2 using menbreg_exploratory, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel 


* * * * * Appendix * * * * *

* * * * Descriptive statistics * * * * 

clear
use Data_IPD

tsset ID_dyad Round

* * Absolute and relative level of individual attack against an outgroup by round * * 

tabulate Round if Atleast_one_group_dead != 1, summarize(Attack_subj_outgroup) 

gen Share_attack_subj_outgroup = Attack_subj_outgroup/Resources_subj
format Share_attack_subj_outgroup %8.2g
tabulate Round if Atleast_one_group_dead != 1, summarize(Share_attack_subj_outgroup) 
graph box Share_attack_subj_outgroup if Atleast_one_group_dead != 1, over(Round) by(UDC) noout

* * * Attacks by subject characteristics * * *

* * First, structuring data by subject * * 

by ID_subject, sort: egen Mean_attack = mean(Attack_subj_outgroup) if Atleast_one_group_dead != 1
by ID_subject, sort: egen Mean_attack_rich = mean(Attack_subj_outgroup_richer) if Atleast_one_group_dead != 1
by ID_subject, sort: egen Mean_attack_poor = mean(Attack_subj_outgroup_poorer) if Atleast_one_group_dead != 1

keep ID_subject Age Work Educ Gender SDO Left_right Me_coop Mean_attack Mean_attack_rich Mean_attack_poor
duplicates drop
drop if Mean_attack == .

gen Me_coop_cat = Me_coop
recode Me_coop_cat (1=0) (2/3=1)

gen Left_right_cat = Left_right
recode Left_right_cat (1/4=0) (5/6=1) (7/10=2)

gen SDO_cat = SDO
recode SDO_cat (-4/-2.25=0) (-2.26/1.5=1) 

gen Age_cat = Age
recode Age_cat (18/20=1) (21/25=2) (26/40=3) (41/70=4)

format Mean_attack Mean_attack_rich Mean_attack_poor %8.3g

* * Now, statistics * * 

tabulate Gender, summarize(Mean_attack) 
ttest Mean_attack, by(Gender)

tabulate Age_cat, summarize(Mean_attack) 
pwcorr Mean_attack Age, sig

tabulate Educ, summarize(Mean_attack) 
anova Mean_attack i.Educ

tabulate Work, summarize(Mean_attack) 
anova Mean_attack i.Work

tabulate Me_coop_cat, summarize(Mean_attack) 
pwcorr Mean_attack Me_coop, sig

tabulate Left_right_cat, summarize(Mean_attack) 
pwcorr Mean_attack Left_right, sig

tabulate SDO_cat, summarize(Mean_attack) 
pwcorr Mean_attack SDO, sig


tabulate Gender, summarize(Mean_attack_rich) 
ttest Mean_attack_rich, by(Gender)

tabulate Age_cat, summarize(Mean_attack_rich) 
pwcorr Mean_attack_rich Age, sig

tabulate Educ, summarize(Mean_attack_rich) 
anova Mean_attack_rich i.Educ

tabulate Work, summarize(Mean_attack_rich) 
anova Mean_attack_rich i.Work

tabulate Me_coop_cat, summarize(Mean_attack_rich) 
pwcorr Mean_attack_rich Me_coop, sig

tabulate Left_right_cat, summarize(Mean_attack_rich) 
pwcorr Mean_attack_rich Left_right, sig

tabulate SDO_cat, summarize(Mean_attack_rich) 
pwcorr Mean_attack_rich SDO, sig


tabulate Gender, summarize(Mean_attack_poor) 
ttest Mean_attack_poor, by(Gender)

tabulate Age_cat, summarize(Mean_attack_poor) 
pwcorr Mean_attack_poor Age, sig

tabulate Educ, summarize(Mean_attack_poor) 
anova Mean_attack_poor i.Educ

tabulate Work, summarize(Mean_attack_poor) 
anova Mean_attack_poor i.Work

tabulate Me_coop_cat, summarize(Mean_attack_poor) 
pwcorr Mean_attack_poor Me_coop, sig

tabulate Left_right_cat, summarize(Mean_attack_poor) 
pwcorr Mean_attack_poor Left_right, sig

tabulate SDO_cat, summarize(Mean_attack_poor) 
pwcorr Mean_attack_poor SDO, sig



* * * * Robustness checks * * * *

clear
use Data_IPD

tsset ID_dyad Round

* * * Envy hypothesis * * *

* * Ingroup-outgroup dyads with ingroup random effects * *

* First: Structuring the data in ingroup-outgroup dyads *

keep Round ID_ingroup Outgroup_number Attack_ingroup_outgroup Resources_outgroup Resources_outgroup_std Resources_ingroup_std UDC Atleast_one_group_dead Attack_outgroup_ingroup_lag_std
duplicates drop

* Now, regressions *

menbreg Attack_ingroup_outgroup Resources_outgroup_std Resources_ingroup_std Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 || ID_ingroup:
outreg2 using nbreg_envy_ingroup_RE, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

menbreg Attack_ingroup_outgroup c.Resources_outgroup_std##i.UDC c.Resources_ingroup_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 || ID_ingroup:
outreg2 using nbreg_envy_ingroup_RE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

	* Margins (unstandardized). Note: I use xtnbreg instead of menbreg (an equivalent multilevel-nbreg command) because bug when computing margins after menbreg
xtset ID_ingroup
xtnbreg Attack_ingroup_outgroup c.Resources_outgroup##i.UDC c.Resources_ingroup_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, iterate(50)
margins UDC, at(Resources_outgroup=(0(100)2500)) predict(nu0)
marginsplot, by(UDC)

menbreg Attack_ingroup_outgroup c.Resources_outgroup_std##c.Resources_outgroup_std Resources_ingroup_std Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 || ID_ingroup:
outreg2 using nbreg_envy_ingroup_RE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

menbreg Attack_ingroup_outgroup c.Resources_outgroup_std##c.Resources_outgroup_std##i.UDC c.Resources_ingroup_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 || ID_ingroup:
outreg2 using nbreg_envy_ingroup_RE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

	* Margins (unstandardized). Note: I use xtnbreg instead of menbreg (an equivalent multilevel-nbreg command) because bug when computing margins after menbreg
xtset ID_ingroup
xtnbreg Attack_ingroup_outgroup c.Resources_outgroup##c.Resources_outgroup##i.UDC c.Resources_ingroup_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, iterate(50)
margins UDC, at(Resources_outgroup=(0(100)2500)) predict(nu0)
marginsplot, by(UDC)

* * Subject-outgroup dyads with subjects fixed effects * *

* First: Going back to the original data in subject-outgroup dyads *
clear
use Data_IPD

tsset ID_dyad Round
xtset ID_subject 

* Now, regressions *

xtnbreg Attack_subj_outgroup Resources_outgroup_std Resources_subj_std Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
outreg2 using nbreg_envy_FE, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

xtnbreg Attack_subj_outgroup c.Resources_outgroup_std##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
outreg2 using nbreg_envy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

	* Margins (unstandardized)
xtnbreg Attack_subj_outgroup c.Resources_outgroup##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
margins UDC, at(Resources_outgroup=(0(100)2500)) predict(iru0)
marginsplot, by(UDC)

xtnbreg Attack_subj_outgroup c.Resources_outgroup_std##c.Resources_outgroup_std Resources_subj_std Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
outreg2 using nbreg_envy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

xtnbreg Attack_subj_outgroup c.Resources_outgroup_std##c.Resources_outgroup_std##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
outreg2 using nbreg_envy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

	* Margins (unstandardized)
xtnbreg Attack_subj_outgroup c.Resources_outgroup##c.Resources_outgroup##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
margins UDC, at(Resources_outgroup=(0(100)2500)) predict(iru0)
marginsplot, by(UDC)

* * Subject-outgroup dyads zero-inflated negative binomial models with standard errors clustered by subjects * *

zinb Attack_subj_outgroup Resources_outgroup_std Resources_subj_std Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, vce(cluster ID_subject) inflate(Resources_outgroup_std Resources_subj_std Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_envy_FE, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

zinb Attack_subj_outgroup c.Resources_outgroup_std##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, vce(cluster ID_subject) inflate(c.Resources_outgroup_std##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_envy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

zinb Attack_subj_outgroup c.Resources_outgroup##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, vce(cluster ID_subject) inflate(c.Resources_outgroup##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std)
margins UDC, at(Resources_outgroup=(0(100)2500))
marginsplot, by(UDC)

zinb Attack_subj_outgroup c.Resources_outgroup_std##c.Resources_outgroup_std Resources_subj_std Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, vce(cluster ID_subject) inflate(c.Resources_outgroup_std##c.Resources_outgroup_std Resources_subj_std Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_envy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

zinb Attack_subj_outgroup c.Resources_outgroup_std##c.Resources_outgroup_std##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, vce(cluster ID_subject) inflate(c.Resources_outgroup_std##c.Resources_outgroup_std##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_envy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

zinb Attack_subj_outgroup c.Resources_outgroup##c.Resources_outgroup##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, vce(cluster ID_subject) inflate(c.Resources_outgroup##c.Resources_outgroup##i.UDC c.Resources_subj_std##i.UDC Attack_outgroup_ingroup_lag_std)
margins UDC, at(Resources_outgroup=(0(100)2500))
marginsplot, by(UDC)


* * * Jealousy hypothesis * * *

* * Ingroup-outgroup dyads with ingroup random effects * *

* First: Structuring the data in ingroup-outgroup dyads *

keep Round ID_ingroup Outgroup_number Attack_ingroup_outgroup Ecocond_outgroup Resources_ingroup_std UDC Atleast_one_group_dead Attack_outgroup_ingroup_lag_std Rank_ingroup Richer_outgroup
duplicates drop

* Now, regressions *

menbreg Attack_ingroup_outgroup i.Ecocond_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 || ID_ingroup:
outreg2 using nbreg_jealousy_ingroup_RE, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

menbreg Attack_ingroup_outgroup i.Ecocond_outgroup##i.UDC c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 || ID_ingroup:
outreg2 using nbreg_jealousy_ingroup_RE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

menbreg Attack_ingroup_outgroup i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 || ID_ingroup:
outreg2 using nbreg_jealousy_ingroup_RE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

	* Margins (unstandardized). Note: I use xtnbreg instead of menbreg (an equivalent multilevel-nbreg command) because bug when computing margins after menbreg
xtset ID_ingroup
xtnbreg Attack_ingroup_outgroup i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 
margins UDC, at(Ecocond_outgroup=(1(1)3) Richer_outgroup =(0(1)1)) predict(nu0)

menbreg Attack_ingroup_outgroup i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 & Richer_outgroup == 1 || ID_ingroup:
outreg2 using nbreg_jealousy_ingroup_RE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

menbreg Attack_ingroup_outgroup i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 & Richer_outgroup == 0 || ID_ingroup:
outreg2 using nbreg_jealousy_ingroup_RE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

* * Subject-outgroup dyads with subjects fixed effects * *

* First: Going back to the original data in subject-outgroup dyads *
clear
use Data_IPD

tsset ID_dyad Round
xtset ID_subject 

* Now, regressions *

xtnbreg Attack_subj_outgroup i.Ecocond_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
outreg2 using nbreg_jealousy_FE, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

xtnbreg Attack_subj_outgroup i.Ecocond_outgroup##i.UDC c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
outreg2 using nbreg_jealousy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

xtnbreg Attack_subj_outgroup i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe
outreg2 using nbreg_jealousy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

	* Margins (unstandardized)
xtset ID_subject
xtnbreg Attack_subj_outgroup i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1, fe 
margins UDC, at(Ecocond_outgroup=(1(1)3) Richer_outgroup =(0(1)1)) 

xtnbreg Attack_subj_outgroup i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 & Richer_outgroup == 1, fe
outreg2 using nbreg_jealousy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

xtnbreg Attack_subj_outgroup i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 & Richer_outgroup == 0, fe
outreg2 using nbreg_jealousy_FE, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

* * Subject-outgroup dyads zero-inflated negative binomial models with standard errors clustered by subjects * *

zinb Attack_subj_outgroup i.Ecocond_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 , vce(cluster ID_subject) inflate(i.Ecocond_outgroup c.Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_jealousy, replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

zinb Attack_subj_outgroup i.Ecocond_outgroup##i.UDC c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 , vce(cluster ID_subject) inflate(i.Ecocond_outgroup##i.UDC c.Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_jealousy, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

zinb Attack_subj_outgroup i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 , vce(cluster ID_subject) inflate(i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_jealousy, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

	* Margins (unstandardized)
zinb Attack_subj_outgroup i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 , vce(cluster ID_subject) inflate(i.Ecocond_outgroup##i.UDC##i.Richer_outgroup c.Attack_outgroup_ingroup_lag_std)
margins UDC, at(Ecocond_outgroup=(1(1)3) Richer_outgroup =(0(1)1)) 

zinb Attack_subj_outgroup i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 & Richer_outgroup == 1, vce(cluster ID_subject) inflate(i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_jealousy, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel

zinb Attack_subj_outgroup i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std if Atleast_one_group_dead != 1 & Richer_outgroup == 0, vce(cluster ID_subject) inflate(i.Ecocond_outgroup##i.UDC i.Rank_ingroup c.Attack_outgroup_ingroup_lag_std)
outreg2 using zinb_jealousy, alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) label excel


